package com.study.test2;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class JarScanner {

//    public static void main(String[] args) {
//        String classpath = System.getProperty("java.class.path");
//
//        // 打印classpath
//        System.out.println("当前运行时的classpath:");
//        System.out.println(classpath);

//    }

    public static void main(String[] args) {
        try {
            // 指定JAR文件路径
            File jarFile = new File("E:\\data\\maven_repository\\cglib\\cglib\\2.2.2\\cglib-2.2.2.jar");
            scanJarFile(jarFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void scanJarFile(File jarFile) throws IOException {
        try (JarFile jar = new JarFile(jarFile)) {
            Enumeration<JarEntry> entries = jar.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                if (entry.getName().endsWith(".class") && !entry.isDirectory()) {
                    // 移除.class扩展名并转换为类名
                    String className = entry.getName()
                            .replace('/', '.')
                            .substring(0, entry.getName().length() - 6);
                    System.out.println("Found class: " + className);
                }
            }
        }
    }
}
